package com.example.annotation;

import java.lang.reflect.Field;

import android.app.Activity;
import android.view.View;

public class InjectUtils {
	public static void init(Activity ac){
		Class<?> c = ac.getClass();
		Field[] dields = c.getDeclaredFields();
		for(Field f : dields){
			ViewInject viewInject = f.getAnnotation(ViewInject.class);
			if(viewInject != null){
				int id = viewInject.value();
				View view = ac.findViewById(id);
				f.setAccessible(true);
				try{
					f.set(ac, view);
				} catch(IllegalAccessException e){
					e.printStackTrace();
				} catch(IllegalArgumentException e){
					e.printStackTrace();
				}
			}
		}
	}
}